package com.csx.orm.mybatis.ext.factory;

import com.csx.orm.mybatis.entity.User;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;

/**
 * <p> what does this class do ? </p>
 *   定义自己的 ObjectFactory, 然后可以在mapper-config.xml 中使用标签
 *   <objectFactory type="com.csx.orm.mybatis.ext.factory.ExtendsObjectFactory"/>
 *   引入
 *
 * <p> How does it work ?</p>
 * <p> Why does it do this ?</p>
 *
 * @author cuisongxu
 * @date 2023/11/13 周一 11:31
 */
public class ExtendsObjectFactory extends DefaultObjectFactory {

    @Override
    public <T> T create(Class<T> type) {
        T t = super.create(type);
        // 判断是否为User类型，如果是，则预初始化值
        if (User.class.equals(type)) {
            User user = (User) t;
            user.setAge(0);
        }
        return t;
    }
}
